<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\tool\Result;
use think\facade\View;
use think\Response;
use app\common\model\Message as MessageModel;
use think\exception\ValidateException;

class Message extends Base
{
    /**
     * 获取疑难解答列表
     */
    public function getList(): Response
    {
        try {
            $map = ['uid' => $this->user->id];
            return Result::fastReturn(MessageModel::getPageList($map, 'id,title,images,comment,rcomment,reply_images,create_time', $this->getPage(), 20, false));
        } catch (\Exception $e) {
            return Result::fail($e->getMessage());
        }
    }
    /**
     * 提交疑难解答
     */
    public function save(): Response
    {
        $param = $this->request->post();
        try {
            $this->validate($param, 'Message');
            return Result::fastReturn(MessageModel::add($param, $this->user));
        } catch (ValidateException $e) {
            return Result::fail($e->getError());
        }
    }

}

